<template>
  <div id="apps" style="margin-left:20px;">
    <div style="margin-right:320px;">
      <el-form id="#create" :model="create" :rules="rules" ref="create" label-width="50%">
        <el-form-item label="法律法规名称" style="float:left;">
          <el-input v-model="create.lawNames"></el-input>
        </el-form-item>
        <el-form-item label="状态" prop="status" style="float:left;">
          <el-select v-model="create.status">
            <el-option
              v-for="item in optionsStatus"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-form>
    </div>
    <div>

    <el-button type="primary" @click="handleSelect()">条件查询</el-button>
    <el-button type="primary" @click="handleAdd()">
      <i class="el-icon-plus iconss"></i> 新增
    </el-button>
    </div>
    <el-table
      :data="lawslist.slice((currpage - 1) * pagesize, currpage * pagesize)"
      border
      stripe
      style="width: 75%"
    >
      <el-table-column type="index" label="序号" width="60" :index="indexMethod"></el-table-column>
      <el-table-column prop="LAW_NAME" label="法律法规名称" width="340"></el-table-column>
      <el-table-column prop="ISSUE_TIME" label="颁布时间" width="180"></el-table-column>
      <el-table-column prop="INPUT_TIME" label="录入时间" width="180"></el-table-column>
      <el-table-column prop="STATUS" label="状态" width="80"></el-table-column>
      <el-table-column prop="operate" label="操作" width="240">
        <template slot-scope="scope">
          <el-button
            type="primary"
            size="mini"
            @click="handleEdit(scope.$index, scope.row,lawslist)"
          >编辑</el-button>
          <el-button
            size="mini"
            type="primary"
            @click="handleLook(scope.$index, scope.row,lawslist)"
          >查看</el-button>
          <el-button
            size="mini"
            type="primary"
            @click="handleDelete(scope.$index,scope.row,lawslist)"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      background
      layout="prev, pager, next, sizes, total, jumper"
      :page-sizes="[5, 10, 15, 20]"
      :page-size="pagesize"
      :total="lawslist.length"
      @current-change="handleCurrentChange"
      @size-change="handleSizeChange"
      style="text-align: center;"
    ></el-pagination>
  </div>
</template>

  <script>
export default {
  name: "lawslist",
  data() {
    return {
      lawslist: [],
      lawName: "",
      currpage: 1,
      issueTime: "",
      pagenum: "",
      pagesize: 10,
      dialogCreateVisible: false,
      createLoading: false,
      create: {
        lawNames: "",
        status: ""
      },
      optionsStatus: [
        {
          value: "1",
          label: "有效"
        },
        {
          value: "0",
          label: "无效"
        }
      ]
    };
  },
  dateFormat(row, column) {
    var date = row[column.property];
    console.log("date  >>>>" + date);
    if (date == undefined) {
      return "";
    }
    return moment(date).format("YYYY-MM-DD HH:mm:ss");
  },
  created() {
    this.getlist();
  },
  methods: {
    getlist() {
      // axios 参数传递
      var params = new URLSearchParams();
      params.append("pagenum", this.currpage);
      params.append("pagesize", this.pagesize);

     this.postRequest("/base/laws/showlist", {
        pagenum: this.currpage,
        pagesize: this.pagesize
      }).then(successResponse => {
          this.lawslist = successResponse.data;
          console.log("data--->" + successResponse.data);
          console.log(successResponse.data[0].status);
          console.log(this.lawslist.length + "<-----数据--->" + this.lawslist);
        })
        .catch(err => {
          console.error(err);
        });
    },
    handleCurrentChange(cpage) {
      this.currpage = cpage;
    },
    handleSizeChange(psize) {
      this.pagesize = psize;
    },
    handleSelect() {
      var params = new URLSearchParams();
      params.append("pagenum", this.currpage);
      params.append("pagesize", this.pagesize);
      console.log("法律法规名称----" + this.create.lawNames);
      console.log("状态----" + this.create.status);
      params.append("lawNames", this.create.lawNames);
      params.append("status", this.create.status);
      this.$axios
        .post("/showlist", params)
        .then(successResponse => {
          this.lawslist = successResponse.data;
          console.log("data--->" + successResponse.data);
          console.log(successResponse.data[0].status);
          console.log(this.lawslist.length + "<-----数据--->" + this.lawslist);
        })
        .catch(err => {
          console.error(err);
        });
    },
    // 编辑方法！
    handleEdit(index, row, tableData) {
      var lawsNos = tableData[index].LAW_NO;
      console.log("查看主键----" + lawsNos);
      // 通过router 路由传递参数 params  push到BlogEdit这个路由中
      this.$router.push({ name: "BlogEdit", params: { lawsId: lawsNos } });
      this.$router.replace({ path: "/edit" });
    },
    // 查看方法！
    handleLook(index, row, tableData) {
      var lawsNos = tableData[index].LAW_NO;
      console.log("查看主键----" + lawsNos);
      // 通过router 路由传递参数 params
      this.$router.push({ name: "BlogLook", params: { lawsNo: lawsNos } });
      this.$router.replace({ path: "/look" });
    },
    // 删除方法！
    handleDelete(index, row, tableData) {
      var lawsNo = tableData[index].LAW_NO;
      console.log("删除主键----" + lawsNo);
      this.$confirm("删除该记录, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          var params1 = new URLSearchParams();
          params1.append("lawsNo", lawsNo);
          this.$axios
            .post("/delete", params1)
            .then(successResponse => {
              console.log("页面刷新");
              if (successResponse.data.code == "200") {
                console.log("页面刷新");
                this.getlist();
              } else {
                this.$message.error("错误消息");
              }
            })
            .catch(err => {
              this.$message.error("错误消息");
            });
        })
        .catch(() => {
          this.$message({
            message: "取消删除",
            type: "success"
          });
        });
    },
    handleAdd() {
      console.log("新增页面跳转");
      this.$router.replace({ path: "/add" });
    },
    indexMethod(index) {
      var index = index + 1;
      return index;
    }
  }
  // created:在模板渲染成html前调用，即通常初始化某些属性值，然后再渲染成视图。
  // mounted:在模板渲染成html后调用，通常是初始化页面完成后，再对html的dom节点进行一些需要的操作。
  // vue init webpack
};
</script> 

<style>
/* #apps {
  text-align: center;
} */
</style>
